home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / freeze-2.lha / freeze / lz.h < prev    next >
C/C++ Source or Header  |  1993-02-22  |  3KB  |  142 lines

  1. extern void InitTree();
  2.  
  3. #ifndef SEGMENTED
  4. # define MAXBITS 16
  5. #else
  6. # ifdef INT_16_BITS
  7. #  define MAXBITS 15
  8. # else
  9. #  define MAXBITS 14
  10. # endif
  11. #endif
  12.  
  13. #ifdef SEGMENTED
  14. # ifdef TINY
  15. #  undef MAXBITS
  16. #  define MAXBITS 13
  17. # endif
  18. #endif
  19.  
  20. #ifndef BITS
  21. # define BITS    MAXBITS
  22. #endif
  23.  
  24. #if BITS < 13
  25. # undef BITS
  26. # define BITS    13      /* 1:1 hash */
  27. #endif
  28.  
  29. #if BITS > MAXBITS
  30. # undef BITS
  31. # define BITS    MAXBITS
  32. #endif
  33.  
  34. /* The following hash-function isn't optimal but it is very fast:
  35.  
  36.     HASH =      ((first + (second << LEN0) +
  37.             (third << LEN1)) & ((1L << BITS) - 1);
  38.  
  39.   The difference of LENs is no more than one bit.
  40. */
  41.  
  42. #define LEN0    ((BITS-8)/2)
  43. #define LEN1    (BITS-8)
  44.  
  45. #define hash_size      (1L << BITS)
  46.  
  47. /* Use native size hash unless required otherwise */
  48. #if defined(SMALL) || defined(TINY)
  49. typedef us_t hash_t;
  50. #else
  51. typedef unsigned hash_t;
  52. #endif  /* SMALL || TINY */
  53.  
  54. extern int       match_position, chain_length;
  55.  
  56. extern hash_t hashtab[], next[];
  57.  
  58. /* Some defines to eliminate function-call overhead */
  59.  
  60. /* Hash function (no more than 16 bits, so we don't need longs */
  61.  
  62. #define hash(p)\
  63.     ((unsigned)(p)[0] + ((unsigned)(p)[1] << LEN0) +\
  64.     ((unsigned)(p)[2] << LEN1))
  65.  
  66. #ifdef FASTHASH
  67. #define hashof(p)\
  68.     (((p)[0] != (p)[1] ? hash(p) : hash(p) + hash((p) + 3)) &\
  69.     ((1L << BITS) - 1))
  70. #else
  71. #define hashof(p)\
  72.     (hash(p) & ((1L << BITS) - 1))
  73. #endif
  74.  
  75. /* Inserting of a node `r' into hashed linked list: `r' becomes
  76.     the head of list.
  77. */
  78.  
  79. #define InsertNode()\
  80. {\
  81.     register uc_t  *key = &text_buf[r & WINMASK];\
  82.     register unsigned p = hashof(key);\
  83.     if (r < MAXDIST) /* wraparound occured */\
  84.         r = rehash(r);\
  85.     next[r & WINMASK] = hashtab[p];\
  86.     hashtab[p] = r;\
  87. }
  88.  
  89. /* This routine inputs the char from stdin and does some other
  90.     actions depending of this char's presence.
  91. */
  92.  
  93. #define Next_Char(N,F)\
  94. {\
  95.     if ((c = getchar()) != EOF) {\
  96.         text_buf[s] = c;\
  97.         if (s < F - 1)\
  98.             text_buf[s + N] = c;\
  99.         s = (s + 1) & (N - 1);\
  100.         in_count++;\
  101.     } else\
  102.         len--;\
  103.     r++;\
  104.     InsertNode();\
  105. }
  106.  
  107. #if defined(__GNUC__)
  108. #if defined(__i386__)
  109. /* Optimizer cannot allocate these registers correctly :( (v1.39) */
  110. #define FIX_SI  asm("si")
  111. #define FIX_DI  asm("di")
  112. #else
  113.  
  114. /* GNU-style register allocations for other processors are welcome! */
  115.  
  116. #define FIX_SI
  117. #define FIX_DI
  118. #endif
  119. #else
  120.  
  121. /* Dummy defines for non-GNU compilers */
  122.  
  123. #define FIX_SI
  124. #define FIX_DI
  125. #endif
  126.  
  127. /* some heuristic to avoid necessity of "-ggg..." */
  128. #define CHAIN_THRESHOLD (LOOKAHEAD / 2)
  129.  
  130. extern int get_next_match();
  131. extern hash_t rehash();
  132.  
  133. #ifdef GATHER_STAT
  134. extern long node_matches, node_compares, node_prolongations;
  135. #endif
  136.  
  137. #ifdef ALLOW_MISALIGN
  138. #define FETCH(array,index) *(us_t*)(&array[index]-1)
  139. #else
  140. #define FETCH(array,index) array[index]
  141. #endif
  142.